解决Springboot2中无法访问在static/image/中的静态图片!终于解决啦 | 您所在的位置:网站首页 › springboot2 解决静态资源无法访问 › 解决Springboot2中无法访问在static/image/中的静态图片!终于解决啦 |
最近使用springboot2做项目发现,存放在resource/templates文件中的html中 竟然访问不到resource/static/image文件下的图片! 我想要在hellozll.html中访问seveny.png这个图片 然后使用了以下方法:(都访问失败)
图片无法显示,图片破了 解决方法:我们要知道Spring Boot 默认的访问静态资源的文件夹有以下四个 1234classpath:/static classpath:/public classpath:/resources classpath:/META-INF/resources我们可以看到,springboot默认可以找到static中的资源文件,但是我在static中又创建了image文件夹 所以啊,springboot在static中没找到seveny.png这个图片,所以就显示不了啊! 怎么解决呢! 在配置文件中加入以下配置 application.yml 的格式 123spring: resources: static-locations: classpath:/templates/,classpath:/static/image/application.properties 的格式 1spring.resources.static-locations=classpath:/templates/,classpath:/static/image/然后再html中直接这样访问图片,就可以啦 1下面是运行的截图!图片好啦 补充: 下面是我的hellozll.html中写的内容
下面是用controller中定义路径去访问hellozll.html文件
|
CopyRight 2018-2019 实验室设备网 版权所有 |